package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.rpcservice.DepotTransferService;
import com.cmc.cloud.cmclink.doc.vo.depotvo.DepotReqVO;
import com.cmc.cloud.cmclink.doc.vo.depotvo.DepotRespVO;
import com.cmc.cloud.cmclink.eqm.api.model.response.DepotDTO;
import com.cmes.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.*;


/**
 * 堆场查询Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 堆场信息")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/depot")
public class DepotController {

    @Resource
    private DepotTransferService depotTransferService;

    @Operation(summary = "查询港口内堆场信息")
    @PostMapping("/queryDepotByPortCode")
    public CommonResult<List<DepotRespVO>> queryDepotByPortCode(@Valid @RequestBody DepotReqVO depotReqVO) {
        List<DepotDTO> depotDtos = depotTransferService.queryDepotByPortCode(depotReqVO.getPortCode(), depotReqVO.getIsCfs(), depotReqVO.getEnabled());
        if (CollectionUtil.isNotEmpty(depotDtos)){
            return CommonResult.success(BeanUtil.copyToList(depotDtos,DepotRespVO.class));
        }else {
            return CommonResult.success(new ArrayList<>());
        }
    }
}
